package top.conangao.system.controller;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
import top.conangao.common.entity.ResponseResult;
import top.conangao.system.domain.SysRole;
import top.conangao.system.service.SysRoleService;

import java.util.List;

/**
 * @author ConanGao
 * @since 1.0
 **/
@RestController
@RequestMapping("/roles")
@RequiredArgsConstructor
public class SysRoleController {
    private final SysRoleService sysRoleService;
    @GetMapping("/{id}")
    public ResponseResult<SysRole> getRole(@PathVariable("id")Long id){
        return ResponseResult.ok("获取单个角色成功",sysRoleService.getById(id));
    }
    
    @GetMapping("/list")
    public ResponseResult<List<SysRole>> listRoles(){
        return ResponseResult.ok("查询角色列表成功",sysRoleService.list());
    }

    @GetMapping("/page")
    public ResponseResult<Page<SysRole>> pageRoles(Page<SysRole> page){
        return ResponseResult.ok("查询角色分页列表成功",sysRoleService.page(page, Wrappers.emptyWrapper()));
    }

    @PostMapping
    public ResponseResult<Void> saveRole(@RequestBody SysRole sysRole){
        sysRoleService.save(sysRole);
        return ResponseResult.ok("添加角色成功");
    }
}
